import 'package:flutter/material.dart';
import 'package:flutter_food/ui/pages/filter/filter.dart';
import 'package:flutter_food/ui/pages/main/main.dart';
import 'package:flutter_food/ui/pages/meal/meal.dart';
import 'package:flutter_food/ui/pages/detail/meal_detail.dart';

//配置全局路由映射
class AppRouter {
  static final String initRoute = MainScreen.routeName;

  static final routes = {
    MainScreen.routeName: (context) => MainScreen(), //根路由
    MealScreen.routeName: (context) => MealScreen(),
    MealDetailScreen.routeName: (context) => MealDetailScreen(),
    // 以Dialog方式启动
    //FilterScreen.routeName: (context) => FilterScreen(),
  };

//配置路由传值
  static final RouteFactory onGenerateRoute = (RouteSettings settings) {
    // 统一处理
    final String name = settings.name;
    final Function pageContentBuilder = routes[name];
    if (pageContentBuilder != null) {
      if (settings.arguments != null) {
        final Route route = MaterialPageRoute(
            builder: (context) =>
                pageContentBuilder(context, arguments: settings.arguments),
            fullscreenDialog: name == FilterScreen.routeName);
        return route;
      } else {
        final Route route = MaterialPageRoute(
            builder: (context) => pageContentBuilder(context));
        return route;
      }
    } else if (name == FilterScreen.routeName) {
      return MaterialPageRoute(
          builder: (context) => FilterScreen(), fullscreenDialog: true);
    }
    return null;
  };
}
